﻿#ifndef IM_Login_h__
#define IM_Login_h__


#define  _DEBUG

#include "Log.h"
#include "IM_Def.h"

#include "Base_Context.h"


class IM_Gate;
class IM_Account;

enum IM_AgentState
{
	SocketConnect,OnLine,OffLine
};

class IM_Socket_Server;


class IM_Agent
{
	
public:
	static IM_Agent *create_agent(IM_Socket_Server * socket_server,int socket_id, IM_Gate * gate);
	unsigned int get_context_handle() { return m_contxt->get_handle(); }
	void send_data_by_socket_tcp(char * buf, int size);
private:

	IM_Agent();
	~IM_Agent();

	void _proc(Base_Message * base_msg);

	void _login_proc(Base_Message * msg);
	void _on_line_proc(Base_Message *msg);
	void _off_line_proc(Base_Message *msg);


private:

	void _login_handler(char * data,int size);
	void _get_friend_list_handler(char * data,int size);
private:
	IM_Gate*				m_gate;       //网关
	Agent_id				m_agent_id;
	int						m_socket_id;
	Base_Context *			m_contxt;
	IM_Socket_Server *		m_socket_server;
	IM_AgentState			m_current_state;
	IM_Account      *       m_acount;
	std::string				m_token;
};


#endif // IM_Login_h__
